home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 38 / sgn_bans.zip / PARSE2.PAS < prev    next >
Pascal/Delphi Source File  |  1985-10-30  |  999b  |  44 lines

  1. { routine to parse a string into sub-strings }
  2.  
  3. Type
  4.   StrArray = array[1..10] of string[12] ;
  5.   CardImage = string[80] ;
  6.  
  7. Procedure Parse2(instring : CardImage ; var Answers : StrArray ;
  8.                  var Entries, MaxEntries : integer) ;
  9.  
  10. { MaxEntries sets max fields to parse. If 0 or -ve, all are parsed }
  11.  
  12. Var j, start : integer ;
  13.  
  14. Label 100, 200, 300, 400 ;
  15.  
  16. begin
  17.   Entries := 0 ;
  18.   j := 0 ;
  19.  
  20. 100:
  21.   { Start, or previous character was a space }
  22.   j := j + 1 ;
  23.   if j > length(instring) then goto 400 ;
  24.   if instring[j] <> ' '
  25.   then
  26.   begin
  27.     entries := entries + 1 ;
  28.     start := j ;
  29.     goto 200 ;
  30.   end
  31.   else goto 100 ;
  32.  
  33. 200:
  34.   { previous character was not a space }
  35.   j := j + 1 ;
  36.   if j > length(instring) then goto 300 ;
  37.   if instring[j] <> ' ' then goto 200 ;
  38. 300:
  39.   Answers[entries] := copy(instring,start,j-start) ;
  40.   if entries = MaxEntries then goto 400 ; { have parsed enough }
  41.   if j < length(instring) then goto 100 ;
  42.  
  43. 400:
  44. end ;